package com.dc.base.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.dc.base.ext.inflateBindingWithGeneric
import com.dc.base.vm.BaseViewModel
import java.lang.reflect.ParameterizedType

abstract class BaseVmVbFragment<VM: BaseViewModel, VB : ViewBinding>: BaseVmFragment<VM>() {

    protected lateinit var mViewBinding: VB

    override fun layoutId(): Int = 0

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
//        val type = javaClass.genericSuperclass as ParameterizedType
//        val aClass = type.actualTypeArguments[1] as Class<*>
//        val method = aClass.getDeclaredMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.java)
//        mViewBinding = method.invoke(null, layoutInflater, container, false) as VB
        mViewBinding =  inflateBindingWithGeneric(inflater,container,false)
        return mViewBinding.root
    }
}